package com.jiumozhi.spring.annotation.process;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author ZouHaiBo
 * @version 1.0, 2021/1/15 11:05
 * @since JDK 1.8
 */
@Component
public class BeanDefinitionRegistryPostProcessorTest implements BeanDefinitionRegistryPostProcessor, PriorityOrdered
{

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException
	{
		// 新增
		BeanDefinition bd = new GenericBeanDefinition();
		bd.setBeanClassName("com.jiumozhi.spring.annotation.Student");
		registry.registerBeanDefinition("student",bd);

		// 查询和修改
		BeanDefinition student = registry.getBeanDefinition("student");
		// 删除
//		registry.removeBeanDefinition("student");

	}



	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
	{
		System.out.println("============= BeanDefinitionRegistryPostProcessorTest invoke beanFactory =========");
	}

	@Override
	public int getOrder()
	{
		return 1;
	}
}
